package com.example.hotelback.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.hotelback.entity.Admin;
import com.example.hotelback.exception.CustomException;
import com.example.hotelback.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public Admin findByCond(String name, String password) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        queryWrapper.eq("password", password);
        Admin admin = adminMapper.selectOne(queryWrapper);
        if(admin == null) {
            throw new CustomException("用户名或密码错误");
        }
        return admin;
    }

    public Admin findById(int id) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        return adminMapper.selectOne(queryWrapper);
    }
}
